package com.aaa.medicine.controller;



import com.aaa.entity.Producer;
import com.aaa.medicine.service.IProducerService;
import com.aaa.medicine.vo.ProducerVo;
import com.aaa.vo.Result;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.List;


/**
 * <p>
 * 生产厂家表 前端控制器
 * </p>
 *
 * @author 王雪桂
 * @since 2023-03-27
 */
@RestController
@RequestMapping("medicine/producer")
public class ProducerController {
    @Autowired
    private IProducerService iProducerService;
    @GetMapping("/getAll")
    public Result<Producer> getAll(Page page, ProducerVo producer){

        Page list= iProducerService.getdAll(page,producer.getProducerName(),producer.getKeywords(),producer.getStatus());
        return new Result(list);
    }
    /**
     * Medicines查询生产厂家下拉框
     */
    @GetMapping("getAll1")
    public Result<List<Producer>> getAll1(){
        List<Producer> list = iProducerService.list();
        return new Result(list);
    }
    /**
     * 添加
     */
    @PostMapping("addProducerMapper")
    public Result addProducerMapper(@RequestBody Producer producer){
        producer.setCreateTime(LocalDateTime.now());
        return new Result(iProducerService.saveOrUpdate(producer));
    }
    //根据id删除
    @DeleteMapping("delById/{producerId}")
    public Result delById(@PathVariable Integer producerId){
        return new Result(iProducerService.removeById(producerId));
    }
    //批量删除
    @PostMapping("delByIds")
    public Result delById(@RequestBody List<Producer> producers){
        producers.forEach((Producer producers1)->{
            boolean b = iProducerService.removeById(producers1.getProducerId());
        });
        return new Result(200,"",true);
    }
}

